class WarehouseController {
    constructor() {
    }

    //函数调用
    SetAllItem(data: any): void {
        console.log(data);

    }

    //显示界面
    ShowDlg(...data) {
        console.log(" SHOW WAREHOUSE DIALOG!!!!!!!!!!!");
        if (!Game.viewWarehouse) {
            Game.viewWarehouse = new view.dlg.warehouse();
            // Game.viewWarehouse.pos(0, Laya.stage.height-260);

            Game.viewFarm.boxGround.addChild(Game.viewWarehouse);
        }

        if (data) {
            Game.viewWarehouse.SetNowRate(data);
        }

        Game.viewWarehouse.ResetScrollView();
        // var adjustX = Laya.stage.width - 360 * this.scalex;
        Game.viewWarehouse.pos(0, 0);
        // let popupEffect = new Laya.Handler(this, this.setPopupEffect);
        // Game.viewWarehouse.popupEffect = popupEffect;
        Game.viewWarehouse.show();
    }

    //关闭显示界面
    CloseDlg() {
        Game.viewWarehouse.close();
    }

    //设置弹出效果
    setPopupEffect() {
        let dlg = Game.viewWarehouse;

    }

    //请求种子列表
    SendSeedReq() {
        // let msgSeedReq = {
        //     charid : PlayerModel.GetData()["charid"]
        // }
        //Game.net.Send("pbwarehouse.SeedReq", msgSeedReq);
    }

    //设置种子数据
    SetSeedData() {
        for (let i in KBEngine.app.player().itemList) {
            let itemData = KBEngine.app.player().itemList[i];
            console.log(itemData)
            WarehouseModel.SetItemCount(itemData.itemId, itemData.number);
        }
    }

    //改变某个种子的数量
    ChangeSeedData(seed_id: number, change_value: number) {
        WarehouseModel.ChangeItemCount(seed_id, change_value);
        Game.viewWarehouse.ResetScrollView();
    }

    //打开某一种稀有度的背包界面
    ShowDlgWithRate(data: number) {
        this.SetSeedData();
        this.ShowDlg(data);
    }


    //使用道具
    haveProp(itemId: number, count: number, customArg: number) {
        ComFun.BaseCall("haveProp", itemId, count, customArg);
    }

    onHaveProp(itemId, count, customArg) {
        this["on_" + Cfg.ItemCfg[Cfg.ItemCfg[itemId]["prop_type"]]["value"]](itemId, count, customArg);
    }

    comfirmUseProp(args: Array<any>, count) {
        this.haveProp(args[0], count, 0);
    }


    //作用在植物上
    prop_type_crop(itemId) {
        this.CloseDlg();
        Game.viewFarm.showFertilize(itemId);
    }
    //作用在账户上
    prop_type_user(itemId, itemNum) {
        let result = this[Cfg.ItemCfg[Cfg.ItemCfg[itemId]["effect_type"]]["value"]](itemId, itemNum, null);
        if (result == 0) return;
        let confirm: view.module.Confirm = new view.module.Confirm("使用 " + Cfg.ItemCfg[itemId]["name"], Cfg.ItemCfg[itemId]["depict"], true, this, "comfirmUseProp", [itemId]);
        confirm.setMaxNum(itemNum);
        confirm.popup();
    }
    //单次使用方式
    prop_type_once(itemId) {
        let confirm: view.module.Confirm = new view.module.Confirm("使用 " + Cfg.ItemCfg[itemId]["name"], Cfg.ItemCfg[itemId]["depict"], false, this, "comfirmUseProp", [itemId]);
        confirm.popup();
    }

    //作用在植物上,服务器返回处理
    on_prop_type_crop(itemId, count, customArg) {
        Game.viewFarm.onHaveFertilize(itemId, count, customArg);
    }

    //作用在账户上,服务器返回处理
    on_prop_type_user(itemId, count, customArg) {
        console.log("on_prop_type_user ==>> customArg: ", customArg, ", itemId: ", itemId, ", count: ", count);
        this["on_" + Cfg.ItemCfg[Cfg.ItemCfg[itemId]["effect_type"]]["value"]](itemId, count, customArg);
        this.ChangeSeedData(itemId, -count);
    }

    //单次使用方式,服务器返回处理
    on_prop_type_once(itemId, count, customArg) {
        console.log("on_prop_type_once ==>> customArg: ", customArg, ", itemId: ", itemId, ", count: ", count);
        this["on_" + Cfg.ItemCfg[Cfg.ItemCfg[itemId]["effect_type"]]["value"]](itemId, count, customArg);
        this.ChangeSeedData(itemId, -count);
    }


    //影响时间
    prop_effect_time(itemId, count, customArg) {
        console.log("prop_effect_time");
        return 1
        //return this[Cfg.ItemCfg[Cfg.ItemCfg[itemId]["effect_supply"]]["value"]](itemId);
    }
    //影响产量
    prop_effect_yield(itemId, count, customArg) {
        console.log("prop_effect_yield");
        return 1
        //return this[Cfg.ItemCfg[Cfg.ItemCfg[itemId]["effect_supply"]]["value"]](itemId);
    }
    //获得道具
    prop_effect_prop(itemId, count, customArg) {
        console.log("prop_effect_prop");
        return 1
    }
    //影响天气
    prop_effect_weather(itemId, count, customArg) {
        console.log("prop_effect_weather");
        return 1
    }
    //影响积分
    prop_effect_score(itemId, count, customArg) {
        console.log("prop_effect_score");
        return 1
    }
    //影响转盘体力
    prop_effect_turntable(itemId, count, customArg) {
        console.log("prop_effect_turntable");
        return 1
    }
    //增加护盾时间
    prop_effect_shield(itemId, count, customArg) {
        if (ShieldModel.GetIsOpen() == 0) {
            let confirm: view.module.Confirm = new view.module.Confirm("使用 " + Cfg.ItemCfg[itemId]["name"], "您还没有领养小狗, 邀请好友帮你领养吧!", false,
                CtrlManager.GetCtrl(CtrlNames.Shield), "ShowInvite", null);
            confirm.popup();
            return 0;
        }
        return 1
    }

    //获得道具,服务器返回
    on_prop_effect_prop(itemId, count, customArg) {
        let luck;
        for (var key in Cfg.LuckDarwCfg) {
            if(customArg == Cfg.LuckDarwCfg[key]["id"])
                luck = Cfg.LuckDarwCfg[key];
        }
        if(luck){
            let prize = new view.dlg.Prize();
            prize.popup();
            prize.darwShow(luck["indexId"], luck["rate"], false);
        } 
    }
    //影响天气,服务器返回
    on_prop_effect_weather(itemId, count, customArg) {
        console.log("影响天气动效");
    }
    //影响积分,服务器返回
    on_prop_effect_score(itemId, count, customArg) {
        console.log("影响积分动效");
    }
    //影响转盘体力,服务器返回
    on_prop_effect_turntable(itemId, count, customArg) {
        console.log("影响转盘体力动效");
    }
    //增加护盾时间,服务器返回
    on_prop_effect_shield(itemId, count, customArg) {
        console.log("增加护盾时间动效");
    }

    //固定值获取
    prop_supply_fixed(itemId) {
        return Cfg.ItemCfg[itemId]["effect"][0];
    }
    //千分率获取
    prop_supply_permille(itemId) {
        return Cfg.ItemCfg[itemId]["effect"][0];
    }
    //内容随机值获取
    prop_supply_textrandom(itemId) {
        let len = Cfg.ItemCfg[itemId]["effect"].length;
        if (len <= 0) return 0;
        let index = ComFun.GetRandomInt(0, len - 1);
        return Cfg.ItemCfg[itemId]["effect"][index];
    }
    //范围随机值获取
    prop_supply_rangerandom(itemId) {
        let min = Cfg.ItemCfg[itemId]["effect"][0];
        let max = Cfg.ItemCfg[itemId]["effect"][1];
        return ComFun.GetRandomInt(min, max);
    }
}